/*
 * Copyright (c) 2011.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.skavookie.expressions.java;

import org.omg.CORBA.Any;
import org.skavookie.expressions.Expr;
import org.skavookie.expressions.ExprVisitor;
import org.skavookie.expressions.TExprWrapper;

/**
 * Created by IntelliJ IDEA.
 * User: joshua
 * Date: 6/2/11
 * Time: 10:36 AM
 * To change this template use File | Settings | File Templates.
 */
abstract class ExprWrapper<T, V extends ExprVisitor> implements TExprWrapper<T> {
    protected final Expr<T> expr;

    public Expr<T> getExpr() {
        return expr;
    }

    public ExprWrapper(Expr<T> expr) {
        this.expr = expr;
    }

    @Override
    public String toString() {
        return expr.toString();
    }

    public boolean equals(Object other) {
        return expr.equals(other);
    }

    @Override
    public int hashCode() {
        return expr.hashCode();
    }

    protected abstract ExprWrapper<T,V> pack(Expr<T> expr);

    public ExprWrapper<T,V> accept(V visitor) {
        return pack(visitor.apply(expr));
    };
}
